# -*- coding: utf-8 -*-
"""
Created on Tue Jun 16 06:29:09 2020

@author: HP
"""


import pandas as pd
from garp import garp_exact

#=============================================================================
#INPUT FILE
#=============================================================================
df = pd.read_csv( 'ITCR_cdata.csv' )
#Get rid of no risk questions
df = df[ (df['pz'] != 66666.) & (df['pw'] != 66666.) ]
ids = sorted( set( df['participantid'] ) )

#Put in edges
df['edges'] = 0
zeros_count = (df[['x','y','z','w']] == 0.).sum(1)
df.loc[ zeros_count >= 1, 'edges' ] = 1
results_df = df[[ 'participantid', 'edges' ]].groupby('participantid').sum()

#=============================================================================
#MODES AND COLUMNS
#=============================================================================

#-------------------
#manage results file
#-------------------
results_file = 'exact_garp.xlsx'

change_flag = False
for pid in ids:
    print('current id: {0}'.format(pid))
    cur_df = df[ df['participantid'] == pid ]
    C = cur_df[['x','y','z','w']].to_numpy()
    P = cur_df[['px','py','pz','pw']].to_numpy()
    results_df.loc[ pid, 'pass' ] = int( garp_exact(C,P) )
    
change_flag = True
if change_flag:
    change_flag = False      
    results_df.to_excel(results_file)
        



